/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.service.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.statistics.Visit;
import com.blandware.atleap.model.core.statistics.SearchCase;

import java.util.List;

/**
 * <p>Business Delegate (Proxy) Interface to handle communication between web
 * and persistence layer.
 * </p>
 * <p><a href="StatisticsManager.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.9 $ $Date: 2006/06/16 15:21:28 $
 */
public interface StatisticsManager {

    /**
     * Returns first free session number.
     *
     * @return first free session number
     */
    public Integer getFirstFreeSessionNumber();

    /**
     * Returns first free visitor number.
     *
     * @return first free visitor number
     */
    public Integer getFirstFreeVisitorNumber();

    /**
     * Initializes StatisticsManager instance.
     */
    public void initialize();

    /**
     * Processes collected raw data, converting it to persisted Visits.
     * Returns number of session that was assigned.
     *
     * @param rawDataList list of RawData instances; contains data that needs
     * to be processed
     * @param containsEntryPoint whether list contains session entry point
     * @param containsLastVisit whether last element in a list is a last
     * @param sessionNumber number of session
     * @return assigned session number
     */
    public Integer processRawData(List rawDataList, boolean containsEntryPoint,
                                  boolean containsLastVisit,
                                  Integer sessionNumber);

    /**
     * Returns filtered/sorted collection of most popular browsers.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopBrowsers(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular OSes.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopOSes(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular inxeding robots.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopRobots(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopPages(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular content resources.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopContentResources(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular referrer urls.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopReferrerUrls(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular referrer domains.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopReferrerDomains(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular entry points which
     * are pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopPagesEntryPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular entry points which
     * are NOT pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopOtherEntryPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular exit points which
     * are pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopPagesExitPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular exit points which
     * are NOT pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopOtherExitPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular search engines.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopSearchEngines(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular search phrases.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopSearchPhrases(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular search words.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopSearchWords(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular screen
     * resolutions.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopScreenResolutions(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular color
     * depths.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopColorDepths(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular search phrases in
     * internal search engine.
     * For each element, count of all visits is obtained. Elements are sorted
     * by 'popularity':  on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopInternalSearchPhrases(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular search words in
     * internal search engine.
     * For each element, count of all visits is obtained. Elements are sorted
     * by 'popularity':  on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopInternalSearchWords(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of visitors.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of visitors
     */
    public PartialCollection listVisitors(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of visitor sessions.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of sessions
     */
    public PartialCollection listVisitorSessions(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of visits.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of visits
     */
    public PartialCollection listVisits(QueryInfo queryInfo);

    /**
     * Returns statistics totals monthly. List of info per year is returned;
     * each element is list of pairs per month; each pair contains total
     * number of visits and number of unique visitors.
     *
     * @return statistics totals
     */
    public List getTotalsMonthly();

    /**
     * Returns statistics totals daily. List of triads is returned: day, total
     * visits, unique visitors.
     *
     * @return statistics totals daily
     */
    public List getTotalsDaily(Integer year, Integer month);

    /**
     * Returns statistics totals hourly. List of triads is returned: hour, total
     * visits, unique visitors.
     *
     * @return statistics totals hourly
     */
    public List getTotalsHourly(Integer year, Integer month, Integer day);

    /**
     * Retrieves a visit by its ID
     *
     * @param visitId ID of visit to retrieve
     * @return retrieved visit
     */
    public Visit retrieveVisit(Long visitId);

    /**
     * Creates a search case.
     *
     * @param searchCase transfer object representing search case to create
     * @return ID of created search case
     */
    public Long createSearchCase(SearchCase searchCase);
}
